package com.sakiko.parameter.config;

import com.sakiko.parameter.listener.CustomChatModelListener;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

/**
 * projectName: com.sakiko.parameter.config
 *
 * @author: sakiko
 * time: 2025/8/24 13:09
 * description:
 */
@Configuration
public class LLMConfig {

    // 基本配置
//    @Bean
//    public ChatModel chatModelQwen() {
//        return OpenAiChatModel.builder()
//                .apiKey(System.getenv("ALIBABA_BAILIAN_API_KEY"))
//                .modelName("qwen-turbo")
//                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
//                .build();
//    }

    @Bean
    public ChatModel chatModelQwen() {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("ALIBABA_BAILIAN_API_KEY"))
                .modelName("qwen-turbo")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                // 日志参数配置
                .logRequests(true)
                .logResponses(true)
                // 监听器
                .listeners(List.of(new CustomChatModelListener()))
                // 重试次数
                .maxRetries(2)
                // 超时设置,指定时间没有接收到响应，请求终端 request time-out
                .timeout(Duration.ofSeconds(10))
                .build();
    }
}
